package com.example.springboottools.gms;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import com.example.springboottools.pic.DataSourceConfig;
import com.google.gson.Gson;

import javax.sql.DataSource;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.*;

public class JsonCon {
    public static void main(String[] args) {

        byte[] byteArray = {123,34,114,101,113,117,101,115,116,73,100,34,58,34,100,48,54,51,51,98,48,55,52,48,98,55,52,102,54,53,57,49,102,48,56,51,48,102,49,48,49,50,54,55,50,102,34,44,34,98,97,116,99,104,78,111,34,58,34,67,79,80,89,50,48,50,52,49,50,49,49,49,55,51,51,56}; // 对应 "Hello World"

        // 使用默认字符集（通常是 UTF-8）将 byte 数组转换为 String
        String str = new String(byteArray, StandardCharsets.UTF_8);
        System.out.println(str); // 输出: Hello World

        // 如果你知道确切的字符集，可以指定它
        String strWithCharset = new String(byteArray, StandardCharsets.UTF_8);
        System.out.println(strWithCharset); // 输出: Hello World

//        String filePath = "D:\\staples\\char[]#170247.txt";
//
//        try {
//            // 读取文件内容到 byte 数组
//            byte[] byteArray = Files.readAllBytes(Paths.get(filePath));
//
//            // 将 byte 数组转换为 String
//            String content = new String(byteArray, StandardCharsets.UTF_8);
//            System.out.println(content.substring(0,1000));
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

//
//        GmsProcessMdmWithBLOBs gmsProcessMdmWithBLOBs = new GmsProcessMdmWithBLOBs();
//        gmsProcessMdmWithBLOBs.setCreatetime(new Date());
//        Gson gson = new Gson();
//        String json = gson.toJson(gmsProcessMdmWithBLOBs);
//        SerializeConfig serializeConfig = new SerializeConfig();
//        // 设置日期格式
//        // 设置日期格式，并指定 Locale 为英文
//        String dateFormat = "MMM dd, yyyy h:mm:ss a";
//        //serializeConfig.put(Date.class, new SimpleDateFormatSerializer(simpleDateFormat.toPattern()));
//        serializeConfig.put(Date.class, new SimpleDateFormatSerializerImpl(dateFormat));
//        String jsonString = JSON.toJSONString(gmsProcessMdmWithBLOBs,serializeConfig);
//        cn.hutool.json.JSON jsonObject = new cn.hutool.json.JSONObject(gmsProcessMdmWithBLOBs);
//        String string = jsonObject.toString();
//        GmsProcessMdmWithBLOBs claaesJson = Helper.getClaaesJson(jsonString, gmsProcessMdmWithBLOBs.getClass());
//        System.out.println(json);
//        System.out.println(jsonString);
//        System.out.println(string);

//
//        Date date = new Date(); // 当前时间，可以替换为指定日期
//
//        // 使用 SimpleDateFormat 格式化日期
//        SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy hh:mm:ss a",Locale.ENGLISH);
//        String formattedDate = sdf.format(date);
//
//        // 输出结果
//        System.out.println(formattedDate); // 输出例如 "Dec 12, 2024 02:41:37 PM"
//
//        // 如果需要将日期对象转换为 JSON 字符串
//        String jsonString = JSON.toJSONString(date, SerializerFeature.WriteDateUseDateFormat);
//        System.out.println(jsonString);


        /*Map<String,List<GmsProcessMergeVo>> dtypeMap = new HashMap<>();
        DataSource dataSource = DataSourceConfig.getDataSource();
        try {
            Connection connection = dataSource.getConnection();
            PreparedStatement ps = connection.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            do {
                Map<String, String> map = new HashMap<>();
                String uuid = rs.getString("UUID");
                String htmlUrl = rs.getString("HTML_URL");
                String sku = rs.getString("SKU");
                map.put("UUID", uuid);
                map.put("HTML", htmlUrl);
                map.put("SKU", sku);
                maps.add(map);
                sb.append("'").append(uuid).append("',");
            } while (rs.next());
        }catch (Exception e){

        }

        List<GmsProcessMergeVo> gmsProcessMergeVos = gmsProcessMergeVoMapper.selectPendingData(page);
        for (GmsProcessMergeVo mergeVo : gmsProcessMergeVos){
            ArrayList<GmsProcessMergeVo> list = new ArrayList<>();
            String dtype = mergeVo.getMdmWithBLOBs().getDtype();
            dtypeMap.put(dtype,list);
        }
        Gson gson = new Gson();
        for (Map.Entry<String, List<GmsProcessMergeVo>> entry : dtypeMap.entrySet()) {
            List<String> mdms = new ArrayList<>();
            for (int i = 0; i < entry.getValue().size(); i++) {
                GmsProcessMergeVo mergeVo = entry.getValue().get(i);
                mdms.add(gson.toJson(mergeVo.getMdmWithBLOBs()));
            }
        }*/
    }

}
